<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
	<title>Welcome to JSF_PrimeFaces_Hibernate Project</title>
</h:head>
<body>
	<ui:composition template="/pages/common/commonLayout.xhtml">
		<ui:define name="content">
		
			<h:form id="formularz">
			<p:panel id="panel">
				<h:messages errorStyle="color: purple;"/>
				<table>
					<tr>
						<td>
							<p:outputLabel value="Login pacjenta" for="uzytkownik" rendered="#{loginBean.loginUser.accType.personel}"/>
						</td>
 			       		<td>
 			       			<p:autoComplete id="uzytkownik" value="#{userMBean.patient.user}" 
 			       				completeMethod="#{userMBean.findUsers}" required="true"
 			       				rendered="#{loginBean.loginUser.accType.personel}"/>
 			       		</td>
					</tr>
					<tr>
						<td colspan="5"><b><h:outputText value="Dane pacjenta:" /></b>
						</td>
					</tr>
					<tr>
						<td><h:outputLabel for="imie" value="Imie:" /></td>
						<td><p:inputText required="true" id="imie"
								value="#{userMBean.patient.firstName}">
								<f:validateLength minimum="2" maximum="20" />
								<f:validator validatorId="polishCharsValidator"/>
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="drugieImie" value="Drugie imie:" /></td>
						<td><p:inputText id="drugieImie"
								value="#{userMBean.patient.middleName}">
								<f:validateLength minimum="2" maximum="20" />
								<f:validator validatorId="polishCharsValidator"/>
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="nazwisko" value="Nazwisko:" /></td>
						<td><p:inputText required="true" id="nazwisko"
								value="#{userMBean.patient.lastName}">
								<f:validateLength minimum="2" maximum="20" />
								<f:validator validatorId="polishCharsValidator"/>
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="pesel" value="Pesel:" /></td>
						<td><p:inputText id="pesel"  required="true"
								value="#{userMBean.patient.pesel}">
								<f:validateRegex pattern="[0-9]{11}" />
								<f:validator validatorId="peselValidator" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="nip" value="Nip:" /></td>
						<td><p:inputText required="false" id="nip"
								value="#{userMBean.patient.nip}">
								<f:validateRegex pattern="[0-9]{10}" />
								<f:validator validatorId="nipValidator" />
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="telefon" value="Telefon:" /></td>
						<td><p:inputText required="true" id="telefon"
								value="#{userMBean.patient.mobilePhone}">
								<f:validateLength minimum="9" maximum="12" />
								<f:validateRegex pattern="[0-9]*" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="email" value="Email:" /></td>
						<td><p:inputText id="email" required="true"
								value="#{userMBean.patient.email}">
								<f:validateLength minimum="4" maximum="50" />
								<f:validator validatorId="emailValidator" />
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="plec" value="Plec:" /></td>
						<td><p:selectOneMenu id="plec" required="true"
								value="#{userMBean.patient.gender}">
								<f:selectItems value="#{enumBean.genderValues}" var="gender"
									itemValue="#{gender}" itemLabel="#{gender.label}" />
							</p:selectOneMenu></td>
					</tr>
					<tr>
						<td><h:outputLabel for="dataUrodzenia" value="Data urodzenia:" /></td>
						<td><p:calendar id="dataUrodzenia" lang="pl" locale="pl" navigator="true" required="true" 
								effect="fold" value="#{userMBean.patient.birthDate}" yearRange="c-70:c+1"/></td>
					</tr>
					<tr height="20px" />
					<tr>
						<td colspan="5"><b><h:outputText value="Adres:" /></b></td>
					</tr>
					<tr>
						<td><h:outputLabel for="ulica" value="Ulica:" /></td>
						<td><p:inputText required="true" id="ulica"
								value="#{userMBean.patient.address.street}">
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel required="true" for="numerUlicy"
								value="Numer:" /></td>
						<td><p:inputText id="numerUlicy"
								value="#{userMBean.patient.address.streetNumber}">
								<f:validateLength minimum="1" maximum="6" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="numerMieszkania" value="Mieszkanie:" /></td>
						<td><p:inputText id="numerMieszkania"
								value="#{userMBean.patient.address.flatNumber}">
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="kodPocztowy" value="Kod pocztowy:" /></td>
						<td><p:inputText required="true" id="kodPocztowy"
								value="#{userMBean.patient.address.postalCode}">
								<f:validateLength minimum="5" maximum="6" />
								<f:validateRegex pattern="[0-9]{2}-?[0-9]{3}" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="poczta" value="Poczta:" /></td>
						<td><p:inputText required="true" id="poczta"
								value="#{userMBean.patient.address.postalTown}">
								<f:validateLength minimum="2" maximum="20" />
							</p:inputText></td>
					</tr>
					<tr height="20px" />
					<tr>
						<td colspan="2"><b><h:outputText value="Dane kontaktowe:" /></b>
						</td>
						<td />
						<td><h:outputText value="Zgodne z powyższymi:" /></td>
						<td><p:selectBooleanCheckbox value="#{userMBean.patient.contactIdentical}">
								<p:ajax event="change" update="table" />
							</p:selectBooleanCheckbox></td>
					</tr>
					</table>
					</p:panel>
					<p:panel id="table">
						<table>
						<c:if test="#{!userMBean.patient.contactNeeded}">
							<tr>
								<td><h:outputLabel for="name" value="Imie i nazwisko:" /></td>
								<td><p:inputText required="true" id="name"
										value="#{userMBean.patient.contact.name}" /></td>
								<td width="50px" />
								<td><h:outputLabel for="c_phone" value="Numer telefonu:" /></td>
								<td><p:inputText required="true" id="c_phone"
										value="#{userMBean.patient.contact.phone}" /></td>
							</tr>
							<tr>
								<h:outputText>
									<strong> Adres </strong>
								</h:outputText>
							</tr>
							<tr>
								<td><h:outputLabel for="c_street" value="Ulica:" /></td>
								<td><p:inputText required="true" id="c_street"
										value="#{userMBean.patient.contact.contactStreet}" /></td>
								<td width="50px" />
								<td><h:outputLabel for="c_streetNumber" value="Numer:" /></td>
								<td><p:inputText required="true" id="c_streetNumber"
										value="#{userMBean.patient.contact.contactStreetNumber}" /></td>
							</tr>
							<tr>
								<td><h:outputLabel for="c_flatNo" value="Mieszkanie:" /></td>
								<td><p:inputText id="c_flatNo"
										value="#{userMBean.patient.contact.contactFlatNumber}" /></td>
								<td width="50px" />
								<td><h:outputLabel for="c_postal" value="Kod pocztowy:" /></td>
								<td><p:inputText required="true" id="c_postal"
										value="#{userMBean.patient.contact.contactPostalCode}">
										<f:validateRegex pattern="[0-9]{2}-?[0-9]{3}" />
									</p:inputText></td>
							</tr>
							<tr>
								<td><h:outputLabel for="c_postalTown" value="Poczta:" /></td>
								<td><p:inputText required="true" id="c_postalTown"
										value="#{userMBean.patient.contact.contactPostalTown}">
										<f:validateRegex pattern="[A-Za-z]*" />
										<f:validateLength minimum="2" maximum="20" />
									</p:inputText></td>
							</tr>
						</c:if>
						</table>
					</p:panel>
					<table>
					<tr height="20px" />
					<tr>
						<td />
						<td />
						<td />
						<td />
						<td align="right"><p:commandButton id="reset" value="Wyczysc"
								action="#{userMBean.reset}" ajax="false" /> <p:commandButton
								id="submit" value="Zapisz" action="#{userMBean.save}"
								ajax="false" /></td>
					</tr>
				</table>
				
			</h:form>
		</ui:define>
	</ui:composition>
</body>
</html>
